<?
include "include/config.php";

$location='setari';

if (!isset($_SESSION['_user']))
    header ("location: login.php");

if ($_SESSION['_level'] != 0)
    header ("location: index.php");
   

if ($_POST['nume_part'] != '')
   mysql_query ("insert into parteneri(nume,web) values('" . $_POST['nume_part'] . "','" . $_POST['adresa_web'] . "')");
    

if ($_GET['sterge'] != '')
    {
    mysql_query ("delete from parteneri where id='" . $_GET['sterge'] . "' ");
    }

if ($_POST['nume_val_mod'] != '')
    {
    mysql_query ("update parteneri set nume='" . $_POST['nume_val_mod'] . "', web='" . $_POST['valoare_val_mod']
                    . "' where id='" . $_POST['id_mod'] . "'");
    }

$sql_partener=mysql_query("select * from parteneri");

while ($val=mysql_fetch_array($sql_partener))
    {
    $partener[] = $val;

    if ($val['id'] == $_GET['modifica'])
        {
        $modifica=$val;
        }
    }


//$smarty->assign("content", $smarty->fetch(tmpd.'parteneri'.tmpl_ext));
include "include/head.php";
?>

<div id = "container">
    <?
    include "include/meniu.php";
    ?>

    <div id = "submenu">
        <div>
            <div>
                <ul>
                    <li><a href = "locatii.php">Locatii</a></li>

                    <li id = "off2"><a href = "#">Parteneri</a></li>
                </ul>
            </div>
        </div>
    </div>

    <div class = "clear">
    </div>

    <div id = "content">
        <div id = "mid">
            <div>
                <br class = "clear"/>

                <?
                if ($_GET['modifica'] == '')
                    {
                ?>

                    <form action = "parteneri.php" method = "post" enctype = "multipart/form-data">
                        <h2>Introduceti Partenerul</h2>

                        <label>Nume Partener</label>

                        <input name = "nume_part" type = "text" class = "tf bb"/>

                        <br class = "clear"/>

                        <label>Adresa Web*</label>

                        <input name = "adresa_web" type = "text" class = "tf bb"/>

                        <br class = "clear"/>

                        <br class = "clear"/>

                        <label>&nbsp;</label>

                        <input type = "submit" name = "adaugare" value = "Adauga" class = "ok"/> <br>
                        * - Introduceti adresa completa ex(HTTTP://www.google.ro)
                    </form>

                <?
                    }
                ?>
            </div>

            <?
            if ($_GET['modifica'] != '')
                {
            ?>

                <div>
                    <form action = "parteneri.php" method = "post" enctype = "multipart/form-data">
                        <p>
                        <h2>Modifica Nume Partener</h2>

                        <label>Nume Partener</label>

                        <input name = "id_mod" type = "hidden" value = "<?= $modifica['id'] ?>"/>

                        <input name = "nume_val_mod" type = "text" value = "<?= $modifica['nume'] ?>" class = "tf bb"/>

                        <br class = "clear"/>

                        <label>Adresa Web*</label>

                        <input name = "valoare_val_mod" type = "text" value = "<?= $modifica['web'] ?>"
                               class = "tf bb"/>

                        <br class = "clear"/>

                        <br class = "clear"/>

                        <label>&nbsp;</label>

                        <input type = "submit" name = "modifica" value = "Modifica" class = "ok"/>
                        <br>
                        * - Introduceti adresa completa ex(HTTTP://www.google.ro)
    </p>
                    </form>
                </div>

            <?
                }
            ?>

            <br class = "clear"/>

            <br class = "clear"/>

            <?
            if (count($partener > 0))
                {
            ?>

                <h2>TABEL PARTENERI</h2>

                <div>
                    <div class = "cell bb ac">Nume Partener
                    </div>

                    <div class = "cell bb ac">Adresa Web
                    </div>

                    <br class = "clear"/>

                <?
                    $j=0;

                    for ($i=0; $i < count($partener); $i++)
                        {
                        if ($j % 2 == 0) $class='cell__';
                        else  $class='cell_';
                ?>

                    <div class = "<?=$class;?> bb ac"><strong><?= $partener[$i]['nume'] ?></strong>
                    </div>

                    <div class = "<?=$class;?> bb ac"><?= $partener[$i]['web'] ?>
                    </div>

                    <div class = "<?=$class;?> ac"><a href = "parteneri.php?modifica=<?= $partener[$i]['id'] ?>">

                        <img src = "imagini/modifica.gif"/> </a>
                    </div>

                    <div class = "<?=$class;?> ac"><a href = "parteneri.php?sterge=<?= $partener[$i]['id'] ?>"
                                                      onclick = "return delete_confirm('Sunteri siguri ca vreti sa stergeti campul <?=$partener[$i]['nume']?>!!!')">

                        <img src = "imagini/sterge.gif"/></a>
                    </div>

                    <br class = "clear"/>

        <?
                $j++;
                        }
        ?>
                </div>

            <?
                }
            ?>
        </div>
    </div>
</div>

<?
include "include/footer.php";
?>